package com.example.demo.controller;

import com.example.demo.model.Product;
import com.example.demo.service.ProductService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class ProductController {
    @Autowired
    private ProductService productService;

    private ObjectMapper objectMapper;
    @RequestMapping("/save")
    public int save(Product product){
        int ret = productService.save(product);
        if(ret==1){
            log.info("保存成功！");
            return 1;
        }else {
            log.info("保存失败！");
            return -1;
        }
    }

    @RequestMapping("/load")
    public List<Product> load(){
        List<Product> products = productService.load();
        return products;
    }
}
